home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / gfx / jpegaga2.lha / jpegAGAsrc / ppm2aga / DisplayGfx.c < prev    next >
C/C++ Source or Header  |  1995-01-07  |  5KB  |  179 lines

  1. /* Screen display routines              */
  2. /* written by Günther Röhrich           */
  3. /* this source is Public Domain         */
  4.  
  5. /* this works only with OS 3.0 or higher */
  6.  
  7.  
  8. #define INTUI_V36_NAMES_ONLY
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/intuitionbase.h>
  13. #include <intuition/screens.h>
  14. #include <graphics/modeid.h>
  15.  
  16.  
  17. #ifndef __GNUC__
  18. #include <clib/intuition_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <pragmas/intuition_pragmas.h>
  21. #include <pragmas/graphics_pragmas.h>
  22. #else
  23. #include <inline/graphics.h>
  24. #include <inline/intuition.h>
  25. #endif
  26.  
  27. #include "ppm2AGA.h"
  28.  
  29. extern struct IntuitionBase *IntuitionBase;
  30. extern int VGAenable;
  31. extern ULONG SMR;
  32. extern ULONG SMR_DisplayID;
  33. struct Screen *my_screen = NULL;
  34. struct Window *my_window = NULL;
  35. struct RastPort temprp; /* a copy of the screen's RastPort */
  36.  
  37. void CloseDisplay(void);
  38.  
  39. /* Initialize the display, colors will be set later */
  40.  
  41. int InitDisplay(int cols, int rows, ULONG Mode, int NumPlanes)
  42. {
  43.   if(IntuitionBase->LibNode.lib_Version >= 39)
  44.   {
  45.     ULONG Depth, DisplayID;
  46.  
  47.     /* Calculate a DisplayID */
  48.     /* this should be done better... */
  49.  
  50.     if(SMR)
  51.     {
  52.       DisplayID = SMR_DisplayID;
  53.     }
  54.     else
  55.     {
  56.       if(VGAenable)
  57.       {
  58.         if(Mode == HAM6 || Mode == HAM8)
  59.         {
  60.           if(cols > 370 || rows > 260)
  61.             DisplayID = VGAPRODUCTHAM_KEY;
  62.           else
  63.             DisplayID = VGALORESHAMDBL_KEY;
  64.         }
  65.         else
  66.         {
  67.           if(cols > 370 || rows >260) 
  68.             DisplayID = VGAPRODUCT_KEY;
  69.           else
  70.             DisplayID = VGALORESDBL_KEY;   
  71.         }
  72.       }
  73.       else
  74.       {  
  75.         if(Mode == 1 || Mode == 2)
  76.           DisplayID = DEFAULT_MONITOR_ID | HAM_KEY;
  77.         else
  78.           DisplayID = DEFAULT_MONITOR_ID;
  79.  
  80.         if(cols > 370) DisplayID |= HIRES;
  81.         if(rows > 280) DisplayID |= LACE;
  82.       }
  83.     }
  84.  
  85.     if(Mode == HAM6) Depth = 6;
  86.     else if(Mode == HAM8) Depth = 8;
  87.     else Depth = NumPlanes;
  88.  
  89.     my_screen = OpenScreenTags(NULL, SA_Width,     (ULONG)cols,
  90.                                      SA_Height,    (ULONG)rows,
  91.                                      SA_Depth,     (ULONG)Depth,
  92.                                      SA_DisplayID, (ULONG)DisplayID,
  93.                                      SA_Type,      (ULONG)CUSTOMSCREEN,
  94.                                      SA_Quiet,     (ULONG)TRUE,
  95.                                      SA_AutoScroll,(ULONG)TRUE,
  96.                                      SA_Overscan,  (ULONG)OSCAN_STANDARD,
  97.                                      TAG_DONE);
  98.  
  99.     if(my_screen)
  100.     {
  101.       /* open a dummy window to allow autoscroll feature      */
  102.       /* if the window fails to open we can continue, but the */
  103.       /* user will not be able to move the screen             */
  104.       my_window = OpenWindowTags(NULL, WA_Left,         (ULONG)0,
  105.                                        WA_Top,          (ULONG)0,
  106.                                        WA_Width,        (ULONG)cols,
  107.                                        WA_Height,       (ULONG)rows,
  108.                                        WA_CustomScreen, my_screen,
  109.                                        WA_NoCareRefresh,(ULONG)TRUE,
  110.                                        WA_Borderless,   (ULONG)TRUE,
  111.                                        WA_Backdrop,     (ULONG)TRUE,
  112.                                        WA_RMBTrap,      (ULONG)TRUE, /* disable screen menu drawing */
  113.                                        TAG_DONE);
  114.  
  115.       /* initialize temprp for use with WritePixelLine8() */
  116.  
  117.       CopyMem(&my_screen->RastPort, &temprp, sizeof(struct RastPort));
  118.       temprp.Layer = NULL;
  119.       /* V39 function */
  120.       temprp.BitMap = AllocBitMap(cols, 1, my_screen->RastPort.BitMap->Depth, 0, my_screen->RastPort.BitMap);
  121.  
  122.       if(temprp.BitMap == NULL)
  123.       {
  124.         CloseDisplay();
  125.         return 0; /* failure */
  126.       }
  127.       return 1; /* success */
  128.     }
  129.   }
  130.   return 0; /* failure */
  131. }
  132.  
  133.  
  134. /* Set a color... */
  135.  
  136. void SetDisplayColor(int ColorNumber, UBYTE r, UBYTE g, UBYTE b)
  137. {
  138.   if(my_screen)
  139.     /* V39 function */
  140.     SetRGB32(&my_screen->ViewPort, (ULONG)ColorNumber, ((ULONG)r << 24),
  141.                                                        ((ULONG)g << 24),
  142.                                                        ((ULONG)b << 24));
  143. }
  144.  
  145.  
  146. /* Close the display */
  147.  
  148. void CloseDisplay(void)
  149. {
  150.   if(my_screen) ScreenToBack(my_screen);
  151.  
  152.   if(temprp.BitMap)
  153.   {
  154.     /* V39 function */
  155.     FreeBitMap(temprp.BitMap);
  156.     temprp.BitMap = NULL;
  157.   }
  158.   if(my_window)
  159.   {
  160.     CloseWindow(my_window);
  161.     my_window = NULL;
  162.   }
  163.   if(my_screen)
  164.   {
  165.     CloseScreen(my_screen);
  166.     my_screen = NULL;
  167.   }
  168. }
  169.  
  170.  
  171. /* display a line of chunky pixel graphics... */
  172.  
  173. void DisplayRow(char *array, int cols, int row)
  174. {
  175.   if(my_screen)
  176.     /* V37 function */
  177.     WritePixelLine8(&my_screen->RastPort, 0, row, cols, array, &temprp);
  178. }
  179.